package cn.fastoo.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public final class JedisDao {

    private static final Logger log = LoggerFactory.getLogger(JedisDao.class);

    private static JedisPool jedisPool;

    public synchronized static Jedis getJedis() {
        if (jedisPool == null) {
            JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
            jedisPoolConfig.setMaxTotal(100);
            jedisPoolConfig.setMaxIdle(3);
            jedisPoolConfig.setMaxWaitMillis(20000);
            jedisPoolConfig.setTestOnBorrow(true);
            jedisPool = new JedisPool(jedisPoolConfig, Constant.REDIS_HOST, Integer.parseInt(Constant.REDIS_PORT), 3000, Constant.REDIS_AUTH);
        }

        return jedisPool.getResource();
    }

    public static void main(String[] ars) throws Exception{


        Jedis jedis = JedisDao.getJedis();
        jedis.select(2);
        System.out.println(jedis);
        jedis.del("running");

    }
}
